package org.rcgwt.generators;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.rcgwt.client.ui.fields.ValidatedTextField;
import org.rcgwt.client.ui.validator.ClientValidator0;
import org.rcgwt.client.ui.validator.IChecker;
import org.rcgwt.client.ui.validator.IConverter;
import org.rcgwt.client.ui.validator.IFilter;
import org.rcgwt.client.ui.validator.IFormatter;
import org.rcgwt.client.ui.validator.IMasker;
import org.rcgwt.client.ui.validator.ISingleton;
import org.rcgwt.client.ui.validator.ITranslator;
import org.rcgwt.client.ui.validator.Parameter;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;

/**
 * Object which can contain all information about a ClientValidator to generate
 * them.
 * 
 * @author Elian ORIOU
 * 
 */

public class ClientValidatorImpl {

	private String validatorName;
	private String className;
	private String superValidatorName;
	private String superClassName;
	private String locales;

	/* Masker attributes */
	private String maskerPattern;
	private String maskerReplacedBy;

	private String filterClass;
	private String translatorClass;
	private String checkerClass;
	private String formatterClass;
	private String converterClass;
	private String maskerClass;

	private List<Parameter> filterParameters;
	private List<Parameter> translatorParameters;
	private List<Parameter> checkerParameters;
	private List<Parameter> formatterParameters;
	private List<Parameter> converterParameters;
	private List<Parameter> maskerParameters;
	private List<Parameter> genericParameters;

	private ClientValidatorImpl parent;
	private static final String DEFAULT_MASKER_CLASS = "org.rcgwt.client.ui.validator.impl.DefaultMasker";

	public ClientValidatorImpl() {
		filterParameters = new ArrayList<Parameter>();
		translatorParameters = new ArrayList<Parameter>();
		checkerParameters = new ArrayList<Parameter>();
		formatterParameters = new ArrayList<Parameter>();
		converterParameters = new ArrayList<Parameter>();
		maskerParameters = new ArrayList<Parameter>();
		genericParameters = new ArrayList<Parameter>();
	}

	public List<Parameter> getFilterParameters() {
		return filterParameters;
	}

	public List<Parameter> getTranslatorParameters() {
		return translatorParameters;
	}

	public List<Parameter> getCheckerParameters() {
		return checkerParameters;
	}

	public List<Parameter> getFormatterParameters() {
		return formatterParameters;
	}

	public String getValidatorName() {
		return validatorName;
	}

	public void setValidatorName(String name) {
		this.validatorName = name;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getFilterClass() {
		return filterClass;
	}

	public void setFilterClass(String filterClass) {
		this.filterClass = filterClass;
	}

	public String getTranslatorClass() {
		return translatorClass;
	}

	public void setTranslatorClass(String translatorClass) {
		this.translatorClass = translatorClass;
	}

	public String getCheckerClass() {
		return checkerClass;
	}

	public void setCheckerClass(String checkerClass) {
		this.checkerClass = checkerClass;
	}

	public String getFormatterClass() {
		return formatterClass;
	}

	public void setFormatterClass(String formatterClass) {
		this.formatterClass = formatterClass;
	}

	public String getMaskerClass() {
		return maskerClass;
	}

	public void setMaskerClass(String maskerClass) {
		this.maskerClass = maskerClass;
	}

	public void addFilterParameter(Parameter p) {
		filterParameters.add(p);
	}

	public void addTranslatorParameter(Parameter p) {
		translatorParameters.add(p);
	}

	public void addCheckerParameter(Parameter p) {
		checkerParameters.add(p);
	}

	public void addFormatterParameter(Parameter p) {
		formatterParameters.add(p);
	}

	public void addGenericParameter(Parameter p) {
		genericParameters.add(p);
	}

	public void addConverterParameter(Parameter p) {
		converterParameters.add(p);
	}

	public void addMaskerParameter(Parameter p) {
		maskerParameters.add(p);
	}

	public List<Parameter> getGenericParameters() {
		return genericParameters;
	}

	public String getConverterClass() {
		return converterClass;
	}

	public void setConverterClass(String converterClass) {
		this.converterClass = converterClass;
	}

	public List<Parameter> getConverterParameters() {
		return converterParameters;
	}

	public String getLocales() {
		return locales;
	}

	public void setLocales(String locales) {
		this.locales = locales;
	}

	public void setSuperClassName(String superClassName) {
		this.superClassName = superClassName;
	}

	public String getSuperClassName() {
		return superClassName;
	}

	public void setSuperValidatorName(String superValidatorName) {
		this.superValidatorName = superValidatorName;
	}

	public String getSuperValidatorName() {
		return superValidatorName;
	}

	public List<Parameter> getMaskerParameters() {
		return maskerParameters;
	}

	public void setMaskerParameters(List<Parameter> maskerParameters) {
		this.maskerParameters = maskerParameters;
	}

	public void setFilterParameters(List<Parameter> filterParameters) {
		this.filterParameters = filterParameters;
	}

	public void setTranslatorParameters(List<Parameter> translatorParameters) {
		this.translatorParameters = translatorParameters;
	}

	public void setCheckerParameters(List<Parameter> checkerParameters) {
		this.checkerParameters = checkerParameters;
	}

	public void setFormatterParameters(List<Parameter> formatterParameters) {
		this.formatterParameters = formatterParameters;
	}

	public void setConverterParameters(List<Parameter> converterParameters) {
		this.converterParameters = converterParameters;
	}

	public void setGenericParameters(List<Parameter> genericParameters) {
		this.genericParameters = genericParameters;
	}

	public void setMaskerReplacedBy(String maskerReplacedBy) {
		this.maskerReplacedBy = maskerReplacedBy;
		Parameter p = new Parameter();
		p.setName("replaced-by");
		p.setValue(maskerReplacedBy);
		this.maskerParameters.add(p);
	}

	public String getMaskerReplacedBy() {
		return maskerReplacedBy;
	}

	public void setMaskerPattern(String maskerPattern) {
		this.maskerPattern = maskerPattern;
		Parameter p = new Parameter();
		p.setName("pattern");
		p.setValue(maskerPattern);
		this.maskerParameters.add(p);
	}

	public String getMaskerPattern() {
		return maskerPattern;
	}

	/**
	 * Sets the parent to <i>cv</i>
	 * 
	 * @param cv
	 *            The parent
	 */

	public void setParent(ClientValidatorImpl cv) {
		this.parent = cv;
	}

	/**
	 * Get the parent
	 * 
	 * @return The parent
	 */

	public ClientValidatorImpl getParent() {
		return this.parent;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((checkerClass == null) ? 0 : checkerClass.hashCode());
		result = prime * result
				+ ((className == null) ? 0 : className.hashCode());
		result = prime * result
				+ ((filterClass == null) ? 0 : filterClass.hashCode());
		result = prime * result
				+ ((formatterClass == null) ? 0 : formatterClass.hashCode());
		result = prime * result
				+ ((translatorClass == null) ? 0 : translatorClass.hashCode());
		result = prime * result
				+ ((validatorName == null) ? 0 : validatorName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ClientValidatorImpl other = (ClientValidatorImpl) obj;
		if (checkerClass == null) {
			if (other.checkerClass != null)
				return false;
		} else if (!checkerClass.equals(other.checkerClass))
			return false;
		if (className == null) {
			if (other.className != null)
				return false;
		} else if (!className.equals(other.className))
			return false;
		if (filterClass == null) {
			if (other.filterClass != null)
				return false;
		} else if (!filterClass.equals(other.filterClass))
			return false;
		if (formatterClass == null) {
			if (other.formatterClass != null)
				return false;
		} else if (!formatterClass.equals(other.formatterClass))
			return false;
		if (translatorClass == null) {
			if (other.translatorClass != null)
				return false;
		} else if (!translatorClass.equals(other.translatorClass))
			return false;
		if (validatorName == null) {
			if (other.validatorName != null)
				return false;
		} else if (!validatorName.equals(other.validatorName))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ClientValidatorImpl [checkerClass=" + checkerClass
				+ ", checkerParameters=" + checkerParameters + ", className="
				+ className + ", converterClass=" + converterClass
				+ ", converterParameters=" + converterParameters
				+ ", filterClass=" + filterClass + ", filterParameters="
				+ filterParameters + ", formatterClass=" + formatterClass
				+ ", formatterParameters=" + formatterParameters
				+ ", genericParameters=" + genericParameters + ", locales="
				+ locales + ", maskerParameters=" + maskerParameters
				+ ", parent=" + parent + ", superClassName=" + superClassName
				+ ", superValidatorName=" + superValidatorName
				+ ", translatorClass=" + translatorClass
				+ ", translatorParameters=" + translatorParameters
				+ ", validatorName=" + validatorName + "]";
	}

	/**
	 * This method permits the generation (at compilation time) of an
	 * ClientValidator Object
	 * 
	 * @param context
	 *            The generation context
	 * @param logger
	 *            The logger
	 * @param defaultValidatorPackage
	 *            The package where create the validator
	 */

	public void createValidator(GeneratorContext context, TreeLogger logger,
			String defaultValidatorPackage) {

		String className = getClassName();
		boolean isChild = false;

		// Factory PrintWriter
		PrintWriter pw = context.tryCreate(logger, defaultValidatorPackage,
				className);
		if (pw == null) {
			Log.error("PrintWriter is null (for Class : " + className + ")");
			return;
		}

		ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(
				defaultValidatorPackage, className);

		// SuperClass Name
		String superClass = getSuperClassName();

		// Validator Elements Classes
		String filterClass = getFilterClass();
		String translatorClass = getTranslatorClass();
		String checkerClass = getCheckerClass();
		String formatterClass = getFormatterClass();
		String converterClass = getConverterClass();
		String maskerClass = getMaskerClass();

		// Parameters
		List<Parameter> filterParameters = getFilterParameters();
		List<Parameter> translatorParameters = getTranslatorParameters();
		List<Parameter> checkerParameters = getCheckerParameters();
		List<Parameter> formatterParameters = getFormatterParameters();
		List<Parameter> converterParameters = getConverterParameters();
		List<Parameter> maskerParameters = getMaskerParameters();
		List<Parameter> genericParameters = getGenericParameters();

		if (superClass != null) {
			composer.addImport(superClass);
			composer.setSuperclass(superClass);
			isChild = true;
		} else {
			composer.addImport(ClientValidator0.class.getName());
			composer.setSuperclass(ClientValidator0.class.getName());
		}

		composer.addImport(ValidatedTextField.class.getName());
		composer.addImport(IFilter.class.getName());
		composer.addImport(ITranslator.class.getName());
		composer.addImport(IChecker.class.getName());
		composer.addImport(IFormatter.class.getName());
		composer.addImport(ISingleton.class.getName());
		composer.addImport(IConverter.class.getName());
		composer.addImport(IMasker.class.getName());
		composer.addImport(List.class.getName());
		composer.addImport(ArrayList.class.getName());
		composer.addImport(Map.class.getName());
		composer.addImport(HashMap.class.getName());
		composer.addImport(Collections.class.getName());

		// Source writer
		SourceWriter sw = composer.createSourceWriter(context, pw);

		// Attributes
		// Validators Elements
		sw.println("private IFilter filter;");
		sw.println("private ITranslator translator;");
		sw.println("private IChecker checker;");
		sw.println("private IFormatter formatter;");
		sw.println("private IConverter converter;");
		sw.println("private IMasker masker;");

		// Validators Elements Parameters
		sw.println("private Map<String, String> genericParams;");
		sw.println("private Map<String, String> filterParams;");
		sw.println("private Map<String, String> translatorParams;");
		sw.println("private Map<String, String> checkerParams;");
		sw.println("private Map<String, String> formatterParams;");
		sw.println("private Map<String, String> converterParams;");
		sw.println("private Map<String, String> maskerParams;");

		// The Constructor
		sw.println("public " + className + "()");
		sw.println("{");

		// Parameters Diffusion
		if (genericParameters.isEmpty() == false) {
			sw.println("genericParams = new HashMap<String, String>("
					+ genericParameters.size() + ");");
			if (isChild == true
					&& parent.getGenericParameters().isEmpty() == false) {
				sw.println("genericParams.putAll(super.getGenericParams());");
			}
			for (int i = 0; i < genericParameters.size(); i++) {
				Parameter p = genericParameters.get(i);
				String name = p.getName();
				String value = p.getValue();
				sw.println("genericParams.put(\"" + name + "\", \"" + value
						+ "\");");
			}
		} else {
			sw.println("genericParams = Collections.emptyMap();");
			if (isChild == true
					&& parent.getGenericParameters().isEmpty() == false) {
				sw.println("genericParams = new HashMap<String, String>();");
				sw.println("genericParams.putAll(super.getGenericParams());");
			}
		}

		if (filterParameters.isEmpty() == false) {
			sw.println("filterParams = new HashMap<String, String>();");
			if (isChild == true
					&& parent.getFilterParameters().isEmpty() == false) {
				sw.println("filterParams.putAll(super.getFilterParams());");
			}
			if (genericParameters.isEmpty() == false
					|| parent.getGenericParameters().isEmpty() == false) {
				sw.println("filterParams.putAll(genericParams);");
			}
			for (int i = 0; i < filterParameters.size(); i++) {
				Parameter p = filterParameters.get(i);
				String name = p.getName();
				String value = p.getValue();
				sw.println("filterParams.put(\"" + name + "\", \"" + value
						+ "\");");
			}
		} else {
			if (isChild == true
					&& parent.getFilterParameters().isEmpty() == false) {
				sw.println("filterParams = new HashMap<String, String>();");
				sw.println("filterParams.putAll(super.getFilterParams());");
				if (genericParameters.isEmpty() == false
						|| parent.getGenericParameters().isEmpty() == false) {
					sw.println("filterParams.putAll(genericParams);");
				}
			} else {
				sw.println("filterParams = genericParams;");
			}
		}

		if (translatorParameters.isEmpty() == false) {
			sw.println("translatorParams = new HashMap<String, String>();");
			if (isChild == true
					&& parent.getTranslatorParameters().isEmpty() == false) {
				sw
						.println("translatorParams.putAll(super.getTranslatorParams());");
			}
			if (genericParameters.isEmpty() == false
					|| parent.getGenericParameters().isEmpty() == false) {
				sw.println("translatorParams.putAll(genericParams);");
			}
			for (int i = 0; i < translatorParameters.size(); i++) {
				Parameter p = translatorParameters.get(i);
				String name = p.getName();
				String value = p.getValue();
				sw.println("translatorParams.put(\"" + name + "\", \"" + value
						+ "\");");
			}
		} else {
			if (isChild == true
					&& parent.getTranslatorParameters().isEmpty() == false) {
				sw.println("translatorParams = new HashMap<String, String>();");
				sw
						.println("translatorParams.putAll(super.getTranslatorParams());");
				if (genericParameters.isEmpty() == false
						|| parent.getGenericParameters().isEmpty() == false) {
					sw.println("translatorParams.putAll(genericParams);");
				}
			} else {
				sw.println("translatorParams = genericParams;");
			}
		}

		if (checkerParameters.isEmpty() == false) {
			sw.println("checkerParams = new HashMap<String, String>();");
			if (isChild == true
					&& parent.getCheckerParameters().isEmpty() == false) {
				sw.println("checkerParams.putAll(super.getCheckerParams());");
			}
			if (genericParameters.isEmpty() == false
					|| parent.getGenericParameters().isEmpty() == false) {
				sw.println("checkerParams.putAll(genericParams);");
			}
			for (int i = 0; i < checkerParameters.size(); i++) {
				Parameter p = checkerParameters.get(i);
				String name = p.getName();
				String value = p.getValue();
				sw.println("checkerParams.put(\"" + name + "\", \"" + value
						+ "\");");
			}
		} else {
			if (isChild == true
					&& parent.getCheckerParameters().isEmpty() == false) {
				sw.println("checkerParams = new HashMap<String, String>();");
				sw.println("checkerParams.putAll(super.getCheckerParams());");
				if (genericParameters.isEmpty() == false
						|| parent.getGenericParameters().isEmpty() == false) {
					sw.println("checkerParams.putAll(genericParams);");
				}
			} else {
				sw.println("checkerParams = genericParams;");
			}
		}

		if (formatterParameters.isEmpty() == false) {
			sw.println("formatterParams = new HashMap<String, String>();");
			if (isChild == true
					&& parent.getFormatterParameters().isEmpty() == false) {
				sw
						.println("formatterParams.putAll(super.getFormatterParams());");
			}
			if (genericParameters.isEmpty() == false
					|| parent.getGenericParameters().isEmpty() == false) {
				sw.println("formatterParams.putAll(genericParams);");
			}
			for (int i = 0; i < formatterParameters.size(); i++) {
				Parameter p = formatterParameters.get(i);
				String name = p.getName();
				String value = p.getValue();
				sw.println("formatterParams.put(\"" + name + "\", \"" + value
						+ "\");");
			}
		} else {
			if (isChild == true) {
				sw.println("formatterParams = new HashMap<String, String>();");
				sw
						.println("formatterParams.putAll(super.getFormatterParams());");
				if (genericParameters.isEmpty() == false
						|| parent.getGenericParameters().isEmpty() == false) {
					sw.println("formatterParams.putAll(genericParams);");
				}
			} else {
				sw.println("formatterParams = genericParams;");
			}
		}

		if (converterParameters.isEmpty() == false) {
			sw.println("converterParams = new HashMap<String, String>();");
			if (isChild == true
					&& parent.getConverterParameters().isEmpty() == false) {
				sw
						.println("converterParams.putAll(super.getConverterParams());");

			}
			if (genericParameters.isEmpty() == false
					|| parent.getGenericParameters().isEmpty() == false) {
				sw.println("converterParams.putAll(genericParams);");
			}
			for (int i = 0; i < converterParameters.size(); i++) {
				Parameter p = converterParameters.get(i);
				String name = p.getName();
				String value = p.getValue();
				sw.println("converterParams.put(\"" + name + "\", \"" + value
						+ "\");");
			}
		} else {
			if (isChild == true
					&& parent.getConverterParameters().isEmpty() == false) {
				sw.println("converterParams = new HashMap<String, String>();");
				sw
						.println("converterParams.putAll(super.getConverterParams());");
				if (genericParameters.isEmpty() == false
						|| parent.getGenericParameters().isEmpty() == false) {
					sw.println("converterParams.putAll(genericParams);");
				}

			} else {
				sw.println("converterParams = genericParams;");
			}
		}

		if (maskerParameters.isEmpty() == false) {
			sw.println("maskerParams = new HashMap<String, String>();");
			if (isChild == true
					&& parent.getMaskerParameters().isEmpty() == false) {
				sw.println("maskerParams.putAll(super.getMaskerParams());");
			}
			if (genericParameters.isEmpty() == false
					|| parent.getGenericParameters().isEmpty() == false) {
				sw.println("maskerParams.putAll(genericParams);");
			}
			for (int i = 0; i < maskerParameters.size(); i++) {
				Parameter p = maskerParameters.get(i);
				String name = p.getName();
				String value = p.getValue();
				sw.println("maskerParams.put(\"" + name + "\", \"" + value
						+ "\");");
			}
		} else {
			if (isChild == true) {
				sw.println("maskerParams = new HashMap<String, String>();");
				sw.println("maskerParams.putAll(super.getMaskerParams());");
				if (genericParameters.isEmpty() == false
						|| parent.getGenericParameters().isEmpty() == false) {
					sw.println("maskerParams.putAll(genericParams);");
				}
			} else {
				sw.println("maskerParams = genericParams;");
			}
		}

		/* Eliminate the "\" parameter value */
		for (Parameter p : genericParameters) {
			String v = p.getValue();
			if (v.contains("\\")) {
				p.setValue(p.getValue().replace("\\", "\\\\"));
			}
		}
		for (Parameter p : filterParameters) {
			String v = p.getValue();
			if (v.contains("\\")) {
				p.setValue(p.getValue().replace("\\", "\\\\"));
			}
		}
		for (Parameter p : translatorParameters) {
			String v = p.getValue();
			if (v.contains("\\")) {
				p.setValue(p.getValue().replace("\\", "\\\\"));
			}
		}
		for (Parameter p : checkerParameters) {
			String v = p.getValue();
			if (v.contains("\\")) {
				p.setValue(p.getValue().replace("\\", "\\\\"));
			}
		}
		for (Parameter p : formatterParameters) {
			String v = p.getValue();
			if (v.contains("\\")) {
				p.setValue(p.getValue().replace("\\", "\\\\"));
			}
		}
		for (Parameter p : converterParameters) {
			String v = p.getValue();
			if (v.contains("\\")) {
				p.setValue(p.getValue().replace("\\", "\\\\"));
			}
		}
		for (Parameter p : maskerParameters) {
			String v = p.getValue();
			if (v.contains("\\")) {
				p.setValue(p.getValue().replace("\\", "\\\\"));
			}
		}

		/* ValidatorElements Instantiations */
		TypeOracle typeOracle = context.getTypeOracle();

		if (isChild == true && filterClass == null) {
			sw.println("filter = super.getFilter();");

		} else if (filterClass != null) {
			if (typeOracle.findType(ISingleton.class.getName())
					.isAssignableFrom(typeOracle.findType(filterClass))) {
				sw.println("filter = (" + filterClass + ") " + filterClass
						+ ".getInstance();");

			} else {
				sw.println("filter = (" + filterClass + ") new " + filterClass
						+ "(filterParams);");
			}
		}
		if (isChild == true && translatorClass == null) {
			sw.println("translator = super.getTranslator();");
		} else if (translatorClass != null) {
			if (typeOracle.findType(ISingleton.class.getName())
					.isAssignableFrom(typeOracle.findType(translatorClass))) {
				sw.println("translator = (" + translatorClass + ") "
						+ translatorClass + ".getInstance();");

			} else {
				sw.println("translator = (" + translatorClass + ") new "
						+ translatorClass + "(translatorParams);");
			}
		}
		if (isChild == true && checkerClass == null) {
			sw.println("checker = super.getChecker();");
		} else if (checkerClass != null) {
			if (typeOracle.findType(ISingleton.class.getName())
					.isAssignableFrom(typeOracle.findType(checkerClass))) {
				sw.println("checker = (" + checkerClass + ") " + checkerClass
						+ ".getInstance();");

			} else {
				sw.println("checker = (" + checkerClass + ") new "
						+ checkerClass + "(checkerParams);");
			}
		}
		if (isChild == true && formatterClass == null) {
			sw.println("formatter = super.getFormatter();");
		} else if (formatterClass != null) {
			if (typeOracle.findType(ISingleton.class.getName())
					.isAssignableFrom(typeOracle.findType(formatterClass))) {
				sw.println("formatter = (" + formatterClass + ") "
						+ formatterClass + ".getInstance();");

			} else {
				sw.println("formatter = (" + formatterClass + ") new "
						+ formatterClass + "(formatterParams);");
			}
		}
		if (isChild == true && converterClass == null) {
			sw.println("converter = super.getConverter();");
		} else if (converterClass != null) {
			if (typeOracle.findType(ISingleton.class.getName())
					.isAssignableFrom(typeOracle.findType(converterClass))) {
				sw.println("converter = (" + converterClass + ") "
						+ converterClass + ".getInstance();");

			} else {
				sw.println("converter = (" + converterClass + ") new "
						+ converterClass + "(converterParams);");
			}
		}
		if (isChild == true && maskerClass == null) {
			sw.println("masker = super.getMasker();");
		} else if (maskerClass != null) {
			sw.println("masker = (" + maskerClass + ") new " + maskerClass
					+ "(maskerParams);");
		} else {
			sw.println("masker = (" + DEFAULT_MASKER_CLASS + ") new "
					+ DEFAULT_MASKER_CLASS + "(maskerParams);");
		}

		sw.println("}");
		sw.println("");

		// Initialize Method
		sw.println("public void initialize(ValidatedTextField textBox)");
		sw.println("{");
		sw.println("textBox.setFilter(filter);");
		sw.println("textBox.setTranslator(translator);");
		sw.println("textBox.setChecker(checker);");
		sw.println("textBox.setFormatter(formatter);");
		sw.println("textBox.setConverter(converter);");
		sw.println("textBox.setMasker(masker);");
		sw.println("}");

		// Getters
		sw.println("protected IFilter getFilter() {");
		sw.println("return filter;");
		sw.println("}");

		sw.println("protected ITranslator getTranslator() {");
		sw.println("return translator;");
		sw.println("}");

		sw.println("protected IChecker getChecker() {");
		sw.println("return checker;");
		sw.println("}");

		sw.println("protected IFormatter getFormatter() {");
		sw.println("return formatter;");
		sw.println("}");

		sw.println("protected IConverter getConverter() {");
		sw.println("return converter;");
		sw.println("}");

		sw.println("protected IMasker getMasker() {");
		sw.println("return masker;");
		sw.println("}");

		sw.println("protected Map<String, String> getGenericParams() {");
		sw.println("return genericParams;");
		sw.println("}");

		sw.println("protected Map<String, String> getFilterParams() {");
		sw.println("return filterParams;");
		sw.println("}");

		sw.println("protected Map<String, String> getTranslatorParams() {");
		sw.println("return translatorParams;");
		sw.println("}");

		sw.println("protected Map<String, String> getCheckerParams() {");
		sw.println("return checkerParams;");
		sw.println("}");

		sw.println("protected Map<String, String> getFormatterParams() {");
		sw.println("return formatterParams;");
		sw.println("}");

		sw.println("protected Map<String, String> getConverterParams() {");
		sw.println("return converterParams;");
		sw.println("}");

		sw.println("protected Map<String, String> getMaskerParams() {");
		sw.println("return maskerParams;");
		sw.println("}");

		sw.commit(logger);
	}

}
